import java.util.Collection;
import java.util.Collections;

/*
 * @lc app=leetcode.cn id=189 lang=java
 *
 * [189] 旋转数组
 */

// @lc code=start
class Solution {
    public void rotate(int[] nums, int k) {
        int n = nums.length;
        if(n<k) k = k%n;
        reverse(nums, 0, n-1);
        reverse(nums, 0, k-1);
        reverse(nums, k, n-1);
    }
    protected void reverse(int[] nums , int start ,int end){
        while(start<end){
            int temp = nums[start];
            nums[start++] = nums[end];
            nums[end--]= temp;
        }
    }
}
// @lc code=end

